package com.srit.base.struts2.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.Validateable;
import com.srit.base.bean.Page;
import com.srit.base.constant.BaseConstant;

/**
 * 基础action类
 * 
 * @author guan
 * 
 */
public class BaseAction extends ActionSupport implements ServletRequestAware,
		ServletResponseAware, SessionAware, Preparable, Validateable {
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected Page page = new Page();
	public static final String JSON = "json";// 全部使用json对象来做页面
	protected Map session;
	protected String uploadPath = ServletActionContext.getServletContext()
			.getRealPath(BaseConstant.FILE_UPLOAD_PATH);
	protected String downloadPath = ServletActionContext.getServletContext()
			.getRealPath(BaseConstant.FILE_DOWNLOAD_PATH);

	/*
	 * (non-Javadoc)
	 * 
	 * @param response
	 * 
	 * @see
	 * org.apache.struts2.interceptor.ServletResponseAware#setServletResponse
	 * (javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param request
	 * 
	 * @see
	 * org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(
	 * javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @throws Exception
	 * 
	 * @see com.opensymphony.xwork2.Preparable#prepare()
	 */
	@Override
	public void prepare() throws Exception {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param session
	 * 
	 * @see
	 * org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

}
